<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>cookie</title>
    <script>
        window.onload=function(ev){
            addCookie("age","11",1,"/","127.0.0.1");
            function addCookie(key,value,day,path,domain){
                //1.处理默认保存路径
                var index=window.location.pathname.lastIndexOf("/");
                var currentPath=window.location.pathname.slice(0,index);
                path=path||currentPath;
                //2.处理默认保存的domian
                domain=domain||document.domain;
                //3.处理默认过期时间
                if(!day){
                    document.cookie=key+"="+value+";path="+path+";domain="+domain+";";
                }else{
                    var date=new Date();
                    date.setDate(date.getDate()+day);
                    document.cookie=key+"="+value+";expires="+date.toGMTString()+";path="+path+";domain="+domain+";";
                }

            }
        }
    </script>

</head>

<body>


</body>

</html>